<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="renderer" content="webkit" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>弹框</title>
    <style type="text/css">
    .popPosition {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
    }
    #pop-container {
        display: none;
        z-index: 999;
    }
    /*遮盖层*/
    #cover-tier {
        background-color: #D9D9D9;
        opacity: 0.5;
    }
    /*弹出层内容*/
    #pop-tier {
        width: 550px;
        height: 350px;
        border: 5px solid #C3C3C3;
        background-color: #fff;
        margin: auto;
        text-align: center;
    }
    /*关闭弹框*/
    #close-pop {
        position: absolute;
        top: 10px;
        right: 10px;
        cursor: pointer;
    }
    </style>
</head>
<body>
    <div>
        <button id="btn">点击弹出层</button>
        <div id="pop-container">
            <div id="cover-tier" class="popPosition"></div>
            <div id="pop-tier" class="popPosition">
                <i id="close-pop">&#10006;</i>
                <p>这里写弹出层内容</p>
            </div>
        </div>
    </div>
    <script type="text/javascript">
    function temp(id) {
        return document.getElementById(id);
    }
    // 点击按钮出现弹出层
    temp('btn').onclick = function() {
        temp('pop-container').style.display = 'block';
    }
    // 点击右上角X弹出层隐藏
    temp('close-pop').onclick = function() {
        temp('pop-container').style.display = 'none';
    }
    </script>
</body>
</html>
